package com.fulu.game.bigdata.realtime.entity

import com.fulu.game.bigdata.realtime.utils.TimeUtils

class KafkaStrategy()

case class Latest() extends KafkaStrategy
case class Earliest() extends KafkaStrategy
case class GroupOffsets() extends KafkaStrategy
case class CurrentDate(millisecond: Long) extends KafkaStrategy

object KafkaStrategy {
  val strategy_latest: String = "latest"
  val strategy_earliest: String = "earliest"
  val strategy_group_offsets: String = "group_offsets"
  val strategy_current_date: String = "current_date"

  def apply(strategy: String): KafkaStrategy = {
      strategy match {
        case KafkaStrategy.strategy_latest => Latest()
        case KafkaStrategy.strategy_earliest => Earliest()
        case KafkaStrategy.strategy_group_offsets => GroupOffsets()
        case KafkaStrategy.strategy_current_date => CurrentDate(TimeUtils.millsOfToday())
        case _ => throw new IllegalArgumentException(s"不支持的 Kafka 启动策略: $strategy")
      }
    }

  /**
   * 兼容老配置才使用的 接口
   */
  @Deprecated
  def apply(isFromBeginning: Boolean): KafkaStrategy = if (isFromBeginning) Earliest() else Latest()
}
